package com.jinyao.exploit.modules.sys.web;

import com.jinyao.exploit.modules.sys.dao.UserDao;
import com.jinyao.exploit.common.base.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/***********************************************************************
 * 文件说明：
 * 创建信息：李晋 2018/12/10 16:26
 * 变更履历： 
 ***********************************************************************/
@Controller
@RequestMapping(value = "${adminPath}/sys/user")
public class UserController {

    @Autowired
    private UserDao userDao;

    private String modules = "sys/";

    @RequestMapping(value = "to/login")
    public String tologin(){
        return modules + "login";
    }

    @RequestMapping(value = "index")
    public String index(){
        return modules + "index";
    }

    @RequestMapping(value = "error")
    public String error(){
        return modules + "error";
    }

    @RequestMapping(value = "login")
    public String login(User user){
        User oldUser = userDao.get(user.getLoginName());
        if(oldUser.getPassword().equals(user.getPassword())){
            return "redirect:" + "/a" + "/sys/user/index";
        }else {
            return "redirect:" + "/a" + "/sys/user/error";
        }
    }
}
